package com.ykzhujiang.lovespirit.labor;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.ykzhujiang.lovespirit.util.Utility;

public class ECNULabor extends Labor {
	public int Fetch(int page_num) {

		int count = 0;
		String url=url_text;
		while (count++ < page_num && url != null) {
			String text = Utility.GetURLText(url + count, connect_times);
			if (text == null) {
				return -1;
			}
			Pattern p = Pattern.compile(thread_pattern);
			Matcher m = p.matcher(text);
			while (m.find()) {
				String raw = m.group();
				raw = url_root + raw.replaceAll("&amp;", "&");
				if (!files.contains(raw)) {
					files.add(raw);
				}
			}
		}
		return 0;
	}

	public void SetBoard(String board) {
		this.board = board;

		thread_pattern = "(?<=<a href=\")(dispbbs\\.asp\\?boardID=" + board
				+ "&amp;ID=\\d{1,6}&amp;page=\\d{1,3})(?=\" title=\")";

		url_text = "http://bbs.yjsy.ecnu.edu.cn/index.asp?boardid=" + board
				+ "&action=&topicmode=0&page=";

		url_root = "http://bbs.yjsy.ecnu.edu.cn/";
	}

	public String GetBorad() {
		return board;
	}

	private String board = "17";

	private String thread_pattern = "(?<=<a href=\")(dispbbs.asp\\?boardID="
			+ board + "&amp;ID=\\d{1,6}&amp;page=\\d{1,3})(?=\" title=\")";
	
	private String url_text = "http://bbs.yjsy.ecnu.edu.cn/index.asp?boardid="
			+ board + "&action=&topicmode=0&page=";

	private String url_root = "http://bbs.yjsy.ecnu.edu.cn/";

}
